package com.yjj.demo.starter.web;

import com.yjj.demo.common.annotation.ApiLimiter;
import com.yjj.demo.common.annotation.QPSLimiter;
import com.yjj.demo.starter.service.TestService;
import com.yjj.demo.starter.vo.TestVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

/**
 *
 *
 * @author yangjiajia
 * @createdAt 2023/1/18 17:31
 */
@RestController
public class TestController {

    @Autowired
    private TestService testService;

    @Value("${black.user.id.list:}")
    private List<String> blackUserIdList;

    @GetMapping("test")
    @ApiLimiter
    public String test(@RequestParam("userId") String userId) {
        return "success" + userId;
    }

    @GetMapping("test1")
    @QPSLimiter
    public String test1(@RequestParam("userId") String userId) {
        return "success" + userId;
    }

    @GetMapping("lock")
    public String lock(@RequestParam("key") String key) {
        return "lock:" + testService.getLock(key);
    }

    @GetMapping("black/list")
    public String blackList() {
        if (null == blackUserIdList) {
            return "none";
        }
        return blackUserIdList.toString();
    }

    @GetMapping("vo")
    public TestVo getVo() {
        return TestVo.builder()
                .money(new BigDecimal("1.30").toString())
                .build();
    }
}
